home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_mc.idb / usr / freeware / lib / mc / extfs / deb.z / deb
Encoding:
Text File  |  1998-10-28  |  3.1 KB  |  138 lines

  1. #!/usr/bin/perl
  2. #
  3. # Written by Fernando Alegre <alegre@debian.org> 1996
  4. #
  5. # Applied patch by Dimitri Maziuk <emaziuk@curtin.edu.au> 1997
  6. #         (to handle new tar format)
  7. #
  8. # Modified by Fernando Alegre <alegre@debian.org> 1997
  9. #         (to handle both new and old tar formats)
  10. #
  11. #
  12. # Copyright (C) 1997 Free Software Foundation
  13. #
  14.  
  15. sub mcdebfs_list
  16. {
  17. #
  18. #    CAVEAT: Hard links are listed as if they were symlinks
  19. #        Empty directories do not appear at all
  20. #
  21.     local($archivename)=@_;
  22.     chop($date=`LC_ALL=C date "+%b %d %Y %H:%M"`);
  23.     chop($info_size=`dpkg -I $archivename | wc -c`);
  24.     $install_size=length($pressinstall);
  25.  
  26.     print "dr-xr-xr-x   1 root     root     0 $date CONTENTS\n";
  27.     print "-r--r--r--   1 root     root     $info_size $date INFO\n";
  28.     print "-r-xr--r--   1 root     root     $install_size $date INSTALL\n";
  29.  
  30.     if ( open(PIPEIN, "dpkg-deb -c $archivename |") )
  31.     {
  32.         while(<PIPEIN>)
  33.         {
  34.             split;
  35.  
  36.             $perm=$_[0]; $owgr=$_[1]; $size=$_[2];
  37.             if($_[3] =~ /^\d\d\d\d\-/) { # New tar format
  38.                 
  39.                 ($year,$mon,$day) = split(/-/,$_[3]);
  40.                 $month = ("Gee","Jan","Feb","Mar","Apr","May","Jun",
  41.                           "Jul","Aug","Sep","Oct","Nov","Dec")[$mon] || "Gee";
  42.                 $time=$_[4];
  43.                 $pathindex=5;
  44.             }
  45.             else {
  46.                 $month=$_[3];
  47.                 $day=$_[4];
  48.                 $time=$_[5];
  49.                 $year=$_[6];
  50.                 $pathindex=7;
  51.             }
  52.             
  53.             $path=$_[$pathindex++];
  54.             $arrow=$_[$pathindex++];
  55.             $link=$_[$pathindex++];
  56.             $link2=$_[$pathindex++];
  57.  
  58.             $owgr=~s!/! !;
  59.             next if $path=~m!/$!;
  60.             if($arrow eq 'link')
  61.             {
  62. # report hard links as soft links
  63.                 $arrow='->'; $link="/$link2"; 
  64.                 substr($perm, 0, 1) = "l";
  65.             }
  66.             if($arrow ne '')
  67.             {
  68.                 $arrow=' ' . $arrow;
  69.                 $link= ' ' . $link;
  70.             }
  71.             print "$perm 1 $owgr $size $month $day $year $time CONTENTS/$path$arrow$link\n";
  72.         }
  73.     }
  74. }
  75.  
  76. sub mcdebfs_copyout
  77. {
  78.     local($archive,$filename,$destfile)=@_;
  79.  
  80.     if($filename eq "INFO")
  81.     {
  82.         system("dpkg-deb -I $archive > $destfile");
  83.     }
  84.     elsif($filename eq "INSTALL")
  85.     {
  86.         if ( open(FILEOUT,">$destfile") )
  87.         {
  88.             print FILEOUT $pressinstall;
  89.             close FILEOUT;
  90.             system("chmod a+x $destfile");
  91.         }
  92.     }
  93.     else
  94.     {
  95.         $filename=~s!^CONTENTS/!!;
  96.         system("dpkg-deb --fsys-tarfile $archive | tar xOf - $filename > $destfile");
  97.     }
  98. }
  99.  
  100. sub mcdebfs_run
  101. {
  102.     local($archive,$filename)=@_;
  103.     if($filename eq "INSTALL")
  104.     {
  105.         print "Installing $archive\n";
  106.         system("dpkg -i $archive");
  107.     }
  108.     else
  109.     {
  110.         $tmpcmd="/tmp/mcdebfs.run.$$";
  111.         &mcdebfs_copyout($archive, $filename, $tmpcmd);
  112.         system("chmod u+x $tmpcmd");
  113.         system($tmpcmd);
  114.         unlink($tmpcmd);
  115.     }
  116. }
  117.  
  118. $pressinstall=<<EOInstall;
  119.  
  120.                               WARNING
  121.      Don't use this method if you are not willing to reinstall everything...
  122.  
  123. This is not a real file. It is a way to install the package you are browsing.
  124.  
  125. To install this package go back to the panel and press Enter on this file.
  126.  
  127. In Debian systems, a package is automatically upgraded when you install a new
  128. version of it. There is no special upgrade option. Install always works.
  129.  
  130. EOInstall
  131.  
  132. if($ARGV[0] eq "list") { shift; &mcdebfs_list(@ARGV); exit 0; }
  133. elsif($ARGV[0] eq "copyout") { shift; &mcdebfs_copyout(@ARGV); exit 0; }
  134. elsif($ARGV[0] eq "run") { shift; &mcdebfs_run(@ARGV); exit 0; }
  135.  
  136. exit 1;
  137.  
  138.